package LeetcodeTest_thirty_two;

//58.最后一个单词的长度
public class lengthOfLastWord
{
    public static void main(String[] args)
    {
        String s=" aworelre  wwrwrw ffd  ";
        System.out.println(Solution.lengthOfLastWord(s));
    }
}
class Solution
{
    public static int lengthOfLastWord(String s)
    {
        if(s.length()==0)
            return 0;
        int length=0;
        for(int i=s.length()-1;i>=0;i--)
        {
            if(s.charAt(i)==' ')
                ;
            else if(i>0 && s.charAt(i)!=' '&& s.charAt(i-1)==' ')
            {
                length++;
                break;
            }
            else
                length++;
        }
        return length;
    }
}